package com.ruoyi.web.controller.note;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.note.domain.NoteLabel;
import com.ruoyi.note.service.INoteLabelService;

/**
 * 笔记标签Controller
 * 
 * @author ruoyi
 * @date 2025-10-12
 */
@RestController
@RequestMapping("/note/label")
public class NoteLabelController extends BaseController
{
    @Autowired
    private INoteLabelService noteLabelService;

    /**
     * 查询笔记标签列表
     */
    @PreAuthorize("@ss.hasPermi('note:label:list')")
    @GetMapping("/list")
    public TableDataInfo list(NoteLabel noteLabel)
    {
        startPage();
        List<NoteLabel> list = noteLabelService.selectNoteLabelList(noteLabel);
        return getDataTable(list);
    }

    /**
     * 导出笔记标签列表
     */
    @PreAuthorize("@ss.hasPermi('note:label:export')")
    @Log(title = "笔记标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NoteLabel noteLabel)
    {
        List<NoteLabel> list = noteLabelService.selectNoteLabelList(noteLabel);
        ExcelUtil<NoteLabel> util = new ExcelUtil<NoteLabel>(NoteLabel.class);
        util.exportExcel(response, list, "笔记标签数据");
    }

    /**
     * 获取笔记标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('note:label:query')")
    @GetMapping(value = "/{labelId}")
    public AjaxResult getInfo(@PathVariable("labelId") Long labelId)
    {
        return success(noteLabelService.selectNoteLabelByLabelId(labelId));
    }

    /**
     * 新增笔记标签
     */
    @PreAuthorize("@ss.hasPermi('note:label:add')")
    @Log(title = "笔记标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NoteLabel noteLabel)
    {
        return toAjax(noteLabelService.insertNoteLabel(noteLabel));
    }

    /**
     * 修改笔记标签
     */
    @PreAuthorize("@ss.hasPermi('note:label:edit')")
    @Log(title = "笔记标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NoteLabel noteLabel)
    {
        return toAjax(noteLabelService.updateNoteLabel(noteLabel));
    }

    /**
     * 删除笔记标签
     */
    @PreAuthorize("@ss.hasPermi('note:label:remove')")
    @Log(title = "笔记标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{labelIds}")
    public AjaxResult remove(@PathVariable Long[] labelIds)
    {
        return toAjax(noteLabelService.deleteNoteLabelByLabelIds(labelIds));
    }
}